﻿using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Oliving.Edge.AuthHelper;

namespace Oliving.Edge.Controllers
{


    public class OlivingControll : ControllerBase
    {

        #region 参数

        /// <summary>
        /// 角色集合
        /// </summary>
        public List<string> _Roles;
        public readonly IHttpContextAccessor _accessor;


        #endregion


        public OlivingControll(IHttpContextAccessor accessor, PermissionRequirement requirement)
        {
            _accessor = accessor;

            var httpContext = _accessor.HttpContext;

            _Roles = (from item in httpContext.User.Claims
                      where item.Type == requirement.ClaimType
                      select item.Value).ToList();


            string userID = (from item in httpContext.User.Claims
                             where item.Type == JwtRegisteredClaimNames.Jti
                             select item.Value).FirstOrDefault();

            string userName = (from item in httpContext.User.Claims
                               where item.Type == ClaimTypes.Name
                               select item.Value).FirstOrDefault();

            string userNameA = _accessor.HttpContext.User.Identity.Name;


            var ddd = _accessor.HttpContext.User;


            var asd = requirement;

        }

    }


}
